package com.house.common.exception;

import com.house.common.result.HttpCodeEnum;
import com.house.common.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Slf4j
@ControllerAdvice
public class ExceptionCatch {

    /**
     * 处理不可控异常
     * @param e
     * @return
     */
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result exception(Exception e) {
        e.printStackTrace();
        log.error("catch exception:{}",e.getMessage());
        return Result.error(HttpCodeEnum.ERROR);
    }


    /**
     * 处理可控异常
     * @param e
     * @return
     */
    @ExceptionHandler(HouseException.class)
    @ResponseBody
    public Result exception(HouseException e) {
        log.error("catch exception:{}",e);
        return Result.error(e.getHttpCodeEnum());
    }



}
